﻿using System.Web.Mvc;
using CourseSystem.Core.Enum;

namespace CourseSystem.Common.Helpers
{
    public class UserAuth : FilterAttribute, IAuthorizationFilter
    {
        public UserTypeEnum UserType;
        public bool IsLimt = false;
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            if (UserHelper.LoginUser != null)
            {
                if (IsLimt)
                {
                    if (UserHelper.LoginUser.UserType == UserType)
                        return;
                    filterContext.Result = new ViewResult { ViewName = "NotFound" };
                    return;
                }

                if (UserHelper.LoginUser.UserType >= UserType)
                    return;
            }
            filterContext.Result = new HttpUnauthorizedResult();
            //跳转到登录页面
            // filterContext.HttpContext.Response.Redirect("http://xxx.com/Account/Login");
        }
    }
}